package junior.sample.support.db.service;

import junior.db.dao.base.IBaseId;
import junior.db.dao.mybatis.base.BaseMapper;
import junior.db.dao.query.AbstractQuery;
import junior.db.service.EntityService;
import junior.sample.support.db.option.Q;
import junior.util.BeanMapper;

/**
 * @author wubo
 * @date 2024/9/10 11:53
 */
public abstract class CommonService<ID, PO extends IBaseId, VO, DTO, Mapper extends BaseMapper<PO, ID>> extends EntityService<ID, PO, VO, DTO, Mapper> {
    
    @Override
    protected PO dtoToPO(DTO dto) {
        if (entityClass.isAssignableFrom(dto.getClass())) {
            return (PO) dto;
        }
        return BeanMapper.copyProperties(dto, entityClass);
    }
    
    @Override
    protected AbstractQuery<?> getQuery() {
        return new Q();
    }
    
    @Override
    protected String idField() {
        return "id";
    }
}
